//package com.bicon.life.core.base.listener;
//
//import com.bicon.life.core.base.bean.SelfResources;
//import com.bicon.life.core.base.event.SpringResourcesRefreshedEvent;
//import lombok.extern.log4j.Log4j;
//import org.apache.commons.collections.map.HashedMap;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.ApplicationListener;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.event.ContextRefreshedEvent;
//import org.springframework.stereotype.Service;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
//import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
//
//import java.util.Date;
//import java.util.Map;
//
///**
// * Created by L on 2017/5/24.
// * 服务启动后，获取url资源发送资源刷新事件
// */
//@Service
//@Log4j
//public class SpringApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
//
//    private boolean isRefreshed = false;
//
//    @Value("${spring.application.name}")
//    String appName;
//
//    @Override
//    public void onApplicationEvent(ContextRefreshedEvent event) {
//        //防止重复执行。
//        try {
//            if (!isRefreshed) {
//                Map<String, String> resourceMap = new HashedMap();
//                RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) event.getApplicationContext().getBean("requestMappingHandlerMapping");
//                Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
//                String path;
//                String method;
//                for (RequestMappingInfo info : map.keySet()) {
//                    path = info.getPatternsCondition().getPatterns().toString();
//                    path = path.replace("[", "").replace("]", "");
//                    method = info.getMethodsCondition().toString();
//                    method = method.replace("[", "").replace("]", "");
//                    if (method.equals("")) {
//                        method = "GET,POST";
//                    }
//                    resourceMap.put("/" + appName + path, method);
//                }
//                SelfResources selfResources = new SelfResources();
//                selfResources.setMap(resourceMap);
//                event.getApplicationContext().publishEvent(new SpringResourcesRefreshedEvent(event.getApplicationContext(), selfResources));
//                isRefreshed = true;
//                System.out.println("application started");
//            } else {
//                System.out.println("context has refreshed!");
//            }
//        } catch (Exception e) {
//            log.info("error", e);
//        }
//
//    }
//
//
//}
